<?php

require_once('Adept/Converter/IConverter.php');

class Adept_Converter_Number implements Adept_Converter_IConverter {

    protected $decimals = 3;
    protected $decimalSeparator = ',';
    protected $thousandsSeparator = ' ';

    public function getAsModel($value) {
        $value = str_replace($this->thousandsSeparator, "", $value);
        $value = str_replace($this->decimalSeparator, ".", $value);
        return floatval($value);
    }

    public function getAsString($number) {
        return number_format($number, $this->decimals, $this->decimalSeparator,
        $this->thousandsSeparator);
    }

    public function getDecimals()
    {
        return $this->decimals;
    }

    public function setDecimals($decimals)
    {
        $this->decimals = $decimals;
    }

    public function getDecimalSeparator()
    {
        return $this->decimalSeparator;
    }

    public function setDecimalSeparator($decimalSeparator)
    {
        $this->decimalSeparator = $decimalSeparator;
    }

    public function getThousandsSeparator()
    {
        return $this->thousandsSeparator;
    }

    public function setThousandsSeparator($thousandsSeparator)
    {
        $this->thousandsSeparator = $thousandsSeparator;
    }

    /*
    public function setAttributes($attributes) {
    $this->decimals = isset($attributes['decimals']) ? $attributes['decimals'] : 3;
    $this->decimalSeparator = isset($attributes['decpoint']) ? $attributes['decpoint'] : ',';
    $this->thousandsSeparator = isset($attributes['thousandssep']) ? $attributes['thousandssep'] : '.';
    }
    */
}

